﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessComponents.Managers;
using BusinessComponents.DomainModels;
using BusinessComponents;

namespace WaterfrontLodge.WebForms.RoomMgt
{
    public partial class RoomView : System.Web.UI.Page
    {
        #region Declaration
        RoomList rmList = new RoomList();
        IRoomTypeMgr typeMgr = ManagerFactory.RoomTypeMgr;
        #endregion

        #region PageLoad
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int roomType;
                int roomStatus;
                string roomNo;

                switch (Request.QueryString.Count)
                {
                    case 0:
                        roomType = 0;
                        roomStatus = -1;
                        roomNo = "";
                        SearchRooms(roomType, roomStatus, roomNo);
                        break;
                    case 2:
                        roomType = Convert.ToInt16(Request.QueryString["RoomType"]);
                        roomStatus = Convert.ToInt16(Request.QueryString["RoomStatus"]);
                        roomNo = "";
                        SearchRooms(roomType, roomStatus, roomNo);
                        break;
                    case 3:
                        roomType = Convert.ToInt16(Request.QueryString["RoomType"]);
                        roomStatus = Convert.ToInt16(Request.QueryString["RoomStatus"]);
                        roomNo = Request.QueryString["RoomNo"];
                        SearchRooms(roomType, roomStatus, roomNo);
                        break;
                }
            }
        }
        #endregion

        protected void grdRoomView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink hlkEdit = (HyperLink)e.Row.FindControl("hlkEdit");
                hlkEdit.NavigateUrl = "/WebForms/Room/RoomEdit.aspx?RoomNo=" + e.Row.Cells[1].Text;
            }
        }

        private void SearchRooms(int roomType, int roomStatus, string roomNo)
        {
            List<ViewRoom> roomList = rmList.SearchRoom(roomType, roomStatus, roomNo);
            Label2.Text = "Total " + roomList.Count.ToString() + " rooms.";
            grdRoomView.DataSource = roomList;
            grdRoomView.DataBind();
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/WebForms/Room/RoomAdd.aspx");
        }

        
    }
}